package core

import (
	"demo/conf"
	"fmt"

	"github.com/jinzhu/gorm"
	_ "gorm.io/driver/mysql"
)

var Db *gorm.DB

func InitDb() {
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", conf.DbUser, conf.DbPassWord, conf.DbHost, conf.DbPort, conf.DbName)
	db, err := gorm.Open("mysql", dsn)
	if err != nil {
		panic("连接数据库失败,err=" + err.Error())
	}
	Db = db
}
